package org.yi.web.friendlink.entity;

import org.yi.core.annotation.TableBind;
import org.yi.core.enums.AccountStateEnums;
import org.yi.core.model.Pager;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

@TableBind(name="f_friendlink")
public class FriendLinkEntity extends Model<FriendLinkEntity>{
	
	private static final long serialVersionUID = 1L;
	
	public static final FriendLinkEntity dao = new FriendLinkEntity();
	
	/**
	 * query by pagination
	 * @param pager
	 * @return
	 */
	public Page<FriendLinkEntity> getPager(Pager pager) {
		return dao.paginate(pager.getPn(), pager.getSize(), "select *", "from f_friend_link");
	}

	/**
	 * delete params
	 * @param ids
	 */
	public void delete(Long... ids) {
		for(Long id : ids) {
			deleteById(id);
		}
	}

	/**
	 * lock params
	 * @param ids
	 */
	public void lock(Long... ids) {
		String sql = "";
		for(Long id : ids) {
			sql = "update f_friend_link set status = " + AccountStateEnums.LOCK.getCode() + " where id = ?";
			Db.update(sql, id);
		}
	}

	/**
	 * unlock params
	 * @param ids
	 */
	public void unlock(Long... ids) {
		String sql = "";
		for(Long id : ids) {
			sql = "update f_friend_link set status = " + AccountStateEnums.NORMAL.getCode() + " where id = ?";
			Db.update(sql, id);
		}
	}
}
